package com.xikeda.controller;
import com.xikeda.model.CourierTable;
import com.xikeda.model.EvaluateTable;
import com.xikeda.model.UserTable;
import com.xikeda.service.imp.AverageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Author Xiao Linqing
 * @date 2020/6/8 13:14
 */
@Controller
public class AverageController {
    @Resource
    private AverageService averageService;
    public AverageService getAverageService() {
        return averageService;
    }
    @Autowired
    public void setAverageService(AverageService averageService) {
        this.averageService = averageService;
    }
    @RequestMapping("/average")
    @ResponseBody
    public String average(HttpServletRequest request, HttpServletResponse response){
        String courier_id=request.getParameter("courier_id");
       // System.out.println(courier_id);
        List<EvaluateTable> list=this.getAverageService().average(courier_id);
        int q=0;
        int x=0;
        if (list != null && list.size() > 0) {
            for (EvaluateTable i : list) {
                //System.out.println(list.size());
                System.out.print(i.getCourier_level() +" ");
                q=q+i.getCourier_level();

            }
            x=q/list.size();
            System.out.println();
            System.out.println("输出的平均值是"+x);
            /*CourierTable courierTable=new CourierTable();
            courierTable.setService_level(x);
            List<CourierTable> list1 = this.getAverageService().updateaverage(String.valueOf(x));*/
        }


        return "demo";
    }
    @RequestMapping("test10")
    public String InquiryExpress1(HttpServletRequest request, HttpServletResponse response){
        return "demo";
    }
}
